package com.zh.freechat.domain.message.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.zh.freechat.domain.chat.model.MsgStatus;
import com.zh.webcommon.common.auditor.mp.SimpleEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Set;


/**
 * 聊天文本消息
 * 双向流动：
 * client1端 ————service中转————>client2端
 * client1端<————service中转———— client2端
 *
 * @author ZH
 * @date 17:17 2021/5/9
 */

@ToString
@Getter
@Setter
@TableName(value = "ch_chat_msg", autoResultMap = true) //range分区
public class ChatMsgPO extends SimpleEntity {
    /**
     * 主键ID 手动生成
     */
    @TableId(type = IdType.INPUT)
    private Long id;

    private Boolean isGroup;

    private String receiver;

    private String sender;
    /**
     * 消息内容
     */
    private String content;

    private Boolean urlRef;

    /**
     * 消息类型：0文本、1图片、2视频、3语音、4文件
     */
    private int type;

    /**
     * 消息状态
     */
    private int status;

    /**
     * 聊天关系ID
     */
    private String chatId;
    /**
     * 会话ID
     */
    private Long convId;

    /**
     * 已读标记
     */
    @TableField(value = "reads_sign", typeHandler = JacksonTypeHandler.class)
    private Set<String> readsSign = Set.of();
    /**
     * 已删除标记
     */
    @TableField(value = "removes_sign", typeHandler = JacksonTypeHandler.class)
    private Set<String> removesSign = Set.of();


    public ChatMsgPO() {
    }

    public void resetStatus() {
        this.status = MsgStatus.CREATE.getValue();
    }

}
